package com.googlecode.connectlet.crypto.digest;

public abstract class SignatureStream extends DigestStream {
	private static final long serialVersionUID = 1L;

	public abstract byte[] sign();
	public abstract boolean verify(byte[] signature);

	protected abstract DigestStream getDigestStream();

	private DigestStream stream = getDigestStream();

	@Override
	public void reset() {
		stream.reset();
	}

	@Override
	public void write(byte[] b, int off, int len) {
		stream.write(b, off, len);
	}

	@Override
	public byte[] digest() {
		return stream.digest();
	}

	public byte[] sign(byte[] data) {
		write(data);
		byte[] result = sign();
		reset();
		return result;
	}

	public boolean verify(byte[] data, byte[] sigBytes) {
		write(data);
		boolean result = verify(sigBytes);
		reset();
		return result;
	}
}